home *** CD-ROM | disk | FTP | other *** search
- //
- // This is a sample plugin dll for nx - network explorer
- // This plugin returns the http server's name
- // Currently plugins run multithreaded
- // To include a plugin in an nx run add use the option -plug
- // And look at the plugins.txt file
- //
- // The input to this function is Sock *s
- // You can get at the servername, port, etc through it
- //
- // How do you output stuff to the user?
- // Fill in s->szBuf with a null terminated string
- // Make SURE s->szBuf is null terminated before you return
- // We do not print here because 255 plugins all trying to
- // print at the same time is not cool.
- // When this function returns, nx prints whatever was in s->szBuf
- //
- // mikejanzen@hotmail.com
- //
-
- #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
-
- #include <windows.h>
- #include <stdio.h>
- #include <winsock2.h>
- #include <time.h>
-
- #include "sock.h"
-
- BOOL APIENTRY DllMain( HANDLE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
-
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
-
-
- extern "C" __declspec(dllexport) int DoSocket(Sock *s)
- {
- unsigned long ioctlarg=0; // used to set socket to nonblocking
- char outputbuf[256],*p,*p2;
- int len;
-
-
-
- //
- // need to set the socket to blocking !!
- // you will almost always want to include this
- // if you dont know what it does, just leave it in
- //
- ioctlsocket(s->m_Sock,FIONBIO,&ioctlarg);
-
- const char inputbuf[]="HEAD / HTTP/1.0\n\n";
- if( send(s->m_Sock,inputbuf,strlen(inputbuf),0) == SOCKET_ERROR )
- return WSAGetLastError();
-
- if( (len = recv(s->m_Sock,outputbuf,sizeof(outputbuf)-1,0)) == SOCKET_ERROR )
- return WSAGetLastError();
-
- // find the server string
- outputbuf[len]=0; // null terminate the buffer
-
- // do some crappy bounds checking -- this code should be better
- // but its good enough for a sample
- if(strlen(outputbuf) < sizeof(s->m_szBuf)){
- if( (p=strstr(outputbuf,"Server: ")) && (p2=strstr(p,"\n")) ){
- p=p+8;
- *p2=0;
- sprintf(s->m_szBuf,"HTTP Server %s",p);
- return 0;
- }
- else
- {
- sprintf(s->m_szBuf,"HTTP Info %s",outputbuf);
- sprintf(s->m_szBuf,"HTTP Server %s",p);
- }
- }
- return 0;
- }
-